<template>
  <div ref="chartRef" style="width: 100%; height: 180px"/>
</template>

<script setup>
import {onMounted, watch} from "vue";
import {useEcharts} from "../../../../hook/ useEcharts";
import * as echarts from "echarts";

const {chartRef, initChart, updateChart} = useEcharts();
const props = defineProps({
  value: {
    type: Object,
    default: () => ({}),
  },
});

const option = {
  tooltip: {
    trigger: 'item',
    axisPointer: { // 坐标轴指示器，坐标轴触发有效
      type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
    }
  },
  grid: {
    left: '2%',
    right: '1%',
    bottom: '12%',
    top: '20%',
    containLabel: true
  },
  legend: {
    data: ['既有系统登记数', '新建系统登记数', '总体系统标准符合率'],
    left: '15%',
    top: '3%',
    textStyle: {
      color: "#fff"
    },
    itemWidth: 15,
    itemHeight: 10,
    itemGap: 25
  },
  dataZoom: [
    {
      type: 'slider',
      show: true,
      height: '10px',
      bottom: '10px',
      left: '10%',
      right: '10%',
      zoomLoxk: true,
      showDetail: false,
      borderColor: '#8FDFFE',
      backgroundColor: '#8fdffe99',
      handleColor: '#8FDFFE',
      handleSize: 10,
      handleStyle: {
        borderColor: '#8FDFFE',
        shadowBlur: 4,
        shadowOffsetX: 1,
        shadowOffsetY: 1,
        shadowColor: '#e5e5e5'
      },
      start: 0,
      end: 10
    },
  ],
  xAxis: {
    type: 'category',
    data: props.value.xData,
    axisLine: {
      lineStyle: {
        color: '#0444AD'
      }
    },
    axisLabel: {
      textStyle: {
        color: "#fff"
      }
    },
    axisTick: {
      show: false,
    },
  },
  yAxis: [{
    type: 'value',
    name: "单位：个",
    nameTextStyle: {
      color: "#fff"
    },
    axisLine: {
      show: false,
      lineStyle: {
        color: '#cdd5e2'
      }
    },
    splitLine: {
      show: false,
    },
    axisLabel: {
      textStyle: {
        color: "#fff"
      }
    },
  },
    {
      type: "value",
      axisLine: {
        lineStyle: {
          color: '#cdd5e2'
        }
      },
      splitLine: {
        show: false,
      },
      axisLabel: {
        show: true,
        formatter: "{value} %", //右侧Y轴文字显示
        textStyle: {
          color: "#fff"
        }
      }
    }
  ],
  series: [{
    name: '既有系统登记数',
    type: 'bar',
    barWidth: '25px',
    itemStyle: {
      normal: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: '#3C7DFB'
        }, {
          offset: 1,
          color: '#0A285F'
        }]),
        barBorderRadius: 4,
      },
    },
    data: props.value.existSysData
  },
    {
      name: '新建系统登记数',
      type: 'bar',
      barWidth: '25px',
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: '#3CE2FB'
          }, {
            offset: 1,
            color: '#0A585F'
          }]),
          barBorderRadius: 4,
        }

      },
      data: props.value.newSysData
    }, {
      name: "总体系统标准符合率",
      type: "line",
      yAxisIndex: 1, //使用的 y 轴的 index，在单个图表实例中存在多个 y轴的时候有用
      smooth: false, //平滑曲线显示
      symbol: "circle", //标记的图形为实心圆
      symbolSize: 7, //标记的大小
      itemStyle: {
        normal: {
          color: '#FFD15C',
          shadowColor: '#fff',
          shadowBlur: 10,
        },
      },
      lineStyle: {
        color: "#ffa43a"
      },

      data: props.value.sysRateData
    }
  ]
};

watch(() => {
  return props.value
}, (newVal) => {
  updateChart({
    xAxis: {
      data: newVal.xData
    },
    series: [{
      name: '既有系统登记数',
      data: newVal.existSysData
    }, {
      name: '新建系统登记数',
      data: newVal.newSysData
    }, {
      name: "总体系统标准符合率",
      data: newVal.sysRateData
    }]
  })
}, {deep: true})

onMounted(() => {
  // 初始化图表
  initChart(option);
});

</script>

<style scoped lang="scss">

</style>
